package com.platform.controller.backend;

import com.platform.base.BaseController;
import com.platform.common.Const;
import com.platform.common.ServerResponse;
import com.platform.pojo.Attachment;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/attachmentController/")
@CrossOrigin(origins = Const.REQUESTURL,maxAge = 3600,allowCredentials = "true")
public class AttachmentController extends BaseController {

    /**
     * 耗材价格查询导入保存附件
     * @param request
     * @return
     */
    @PostMapping("consumablesImportFile.do")
    public ServerResponse<Attachment> consumablesImportFile(@RequestParam(value = "pageName") String pageName,
            @RequestParam("multipartFile") MultipartFile multipartFile,
                                                            HttpServletRequest request){

        return iAttachmentService.saveFile(pageName,multipartFile,request);
    }

    /**
     * 上传图片附件
     * @param pageName
     * @param entityName
     * @param entityType
     * @param id
     * @param multipartFile
     * @param request
     * @return
     */
    @PostMapping("uploadImage.do")
    public ServerResponse<Attachment> uploadImage(@RequestParam(value = "pageName") String pageName,
                                                  @RequestParam(value = "entityName") String entityName,
                                                  @RequestParam(value = "entityType") String entityType,
                                                  @RequestParam(value = "id") String id,
                                                  @RequestParam("multipartFile") MultipartFile multipartFile,
                                                  HttpServletRequest request){
        return iAttachmentService.uploadImage(pageName,entityName,entityType,id,multipartFile,request);
    }

    /**
     * 上传图片地址2
     * @param pageName
     * @param entityName
     * @param entityType
     * @param id
     * @param multipartFile
     * @param request
     * @return
     */
    @PostMapping("uploadImage2.do")
    public ServerResponse<Attachment> uploadImage2(@RequestParam(value = "pageName") String pageName,
                                                  @RequestParam(value = "entityName") String entityName,
                                                  @RequestParam(value = "entityType") String entityType,
                                                  @RequestParam(value = "id") String id,
                                                  @RequestParam("multipartFile2") MultipartFile multipartFile,
                                                  HttpServletRequest request){
        return uploadImage(pageName,entityName,entityType,id,multipartFile,request);
    }



}
